package 生产者消费者模型;

public class Consumer_02 implements Runnable {

    Data data = null;

    public Consumer_02(Data data) {
        this.data = data;
    }

    @Override
    public void run() {
        for (int i = 0; i < 1000; i++) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            if (data.getDataLen() <= 2) {
                try {
                    Thread.sleep(3000);
                    System.out.println("产品少，消费者2等待");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }


            try {
                data.deleteData();
                System.out.println("消费者2，长度为：" + data.getDataLen());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
